package com.qd.p2p.web.action.user;

import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.user.UserPayPasswordService;
import com.qdlc.p2p.biz.util.ValidCodeSender;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.common.constant.NoticeTplNid;
import com.qdlc.p2p.common.core.ReturnResult;
import com.qdlc.p2p.common.util.MessageCheck;
import com.qdlc.p2p.dal.dto.User;

/**
 * 修改、重置交易密码
 * @author linya 2016-02-18
 */
public class UserPayPasswordAction extends BaseAction<User> implements ModelDriven<User>{

	@Resource
	UserPayPasswordService userPayPasswordService;
	
    /**
     * [交易密码][修改]
     */
    @Action("/member/security/modifyPaypwd")
    public void modifyPaypwd() throws Exception {
        User user = getSessionUser();
        String payPassword = paramString("payPwd");
        String newPayPassword = paramString("newPayPwd");
        String confirmNewPayPassword = paramString("confirmNewPayPwd");
        ReturnResult result = userPayPasswordService.modifyPayPassword(user, payPassword, newPayPassword, confirmNewPayPassword);
        printWebResult(result.getErrorInfo(), result.isSuccess());
    }
    
    /**
     * [交易密码][重置][获取验证码]
     */
    @Action("/member/security/getPaypwdCode")
    public void getPaypwdCode() throws Exception {
        User user = getSessionUser();
        MessageCheck messageCheck=new MessageCheck();
        messageCheck.mobileAdd(user.getMobilePhone());
        ReturnResult result = ValidCodeSender.newInstance().sendCodeByPhone(user,
                user.getMobilePhone(), NoticeTplNid.NOTICE_GET_PAYPWD);
        printWebResult(result.getErrorInfo(), result.isSuccess());
    }

    /**
     * [交易密码][重置]
     */
    @Action("/member/security/resetPaypwd")
    public void resetPaypwd() throws Exception {
        User user = getSessionUser();
        String code = paramString("code");
        String newPayPassword = paramString("newPayPwd");
        String confirmNewPayPassword = paramString("confirmNewPayPwd");
        ReturnResult result = userPayPasswordService.modifyResetPayPassword(user, code, newPayPassword, confirmNewPayPassword);
        printWebResult(result.getErrorInfo(), result.isSuccess());
    }
    
}
